<extend name="Public/base"/>

<block name="body">
	<!-- 标题 -->
	<div class="am-cf am-u-md-12 header-title">
		<h2>{$title|htmlspecialchars}<if condition="$suggest">（{$suggest|htmlspecialchars}）</if></h2>
	</div>

	<php>
	foreach($searches as $search){
		if($_REQUEST[$search['name']]){
			$show=1;
		}
	}
	</php>

	<div class="am-cf am-u-md-12 <eq name='show' value=''>am-hide</eq>" id="search_form">
		<form id="searchForm" method="get" action="{$searchPostUrl}" class="form-dont-clear-url-param">
			<div class="search-form  cf " style="margin-bottom: 10px">
				<table class="am-table am-table-striped">
					<volist name="searches" id="search">
						<!--判断搜索选项是TEXT还是SELECT-->
						<if condition="$search['type'] == 'select'">
							<tr style="line-height: 28px">
								<td>{$search.title}</td>
								<td>
									<select size="1" name="{$search['name']}" class="search-input form-control form-input-width">
										<option value="">全部</option>
										<volist name="search['arrvalue']" id="svo">
											<option value="{$svo.id}" <eq name="svo.id" value="$_GET[$search['name']]">selected</eq>
											>{$svo.value}
										</option>
									</volist>
								</select>
							</td>
							<td>{$search.des}</td>
						</tr>
						<else/>
						<tr style="line-height: 28px">
							<td>{$search.title}</td>
							<td>
								<input style="float: none" type="text" name="{$search.name}" class="search-input form-control form-input-width"	value="{:I($search['name'])}"></td>
							<td>{$search.des}</td>
						</tr>
					</if>
				</volist>
				<tr>
					<td></td>
					<td>
						<div class="am-btn-group">
							<input type="submit" class="am-btn am-btn-primary" value="确定"/>
							<button class="ajax-post am-btn am-btn-danger" onclick="toggle_search()">关闭</button>
						</div>
					</td>
					<td></td>
				</tr>
			</table>
		</div>
		</form>
	</div>
	<!-- 按钮工具栏 -->
	<div class="am-cf am-u-md-12">
		<div class="am-fl">
			<if condition="count($searches) gt 0">
			<button class="am-btn submit-btn" url="?status=-1" target-form="ids" style="padding: 6px 16px;" onclick="toggle_search()">搜索</button>
			</if>

			<div class="am-btn-group">
			<volist name="buttonList" id="button">
			<{$button.tag} {$button.attr}>{$button.title|htmlspecialchars}</{$button.tag}>&nbsp;
			</volist>
			</div>
			<php>
			foreach($selects as $select){
				if($_REQUEST[$select['name']]){
					$show=1;
				}
			}
			</php>
			<!-- 选择框select -->
			<style>
			.oneselect{display: inline-block; margin-left: 10px;}
			.oneselect .title{float: left; line-height: 32px;}
			.oneselect .select_box{float: left; line-height: 32px;}
			.oneselect .select_box select{min-width: 200px;}
			</style>
			<div class="am-fr" >
				<form id="selectForm" method="get" action="{$selectPostUrl}" class="form-dont-clear-url-param">
					<volist name="selects" id="select">
						<div class="oneselect">
							<div class="title">{$select.title}</div>
							<div class="select_box">
								<select name="{$select['name']}" data-role="select_text" class="form-control">
									<volist name="select['arrvalue']" id="svo">
										<option value="{$svo.id}" <eq name="svo.id" value="$_GET[$select['name']]">selected</eq>
										>{$svo.value}
									</option>
								</volist>
							</select>
						</div>
					</div>
				</volist>
				</form>
			</div>
		</div>
	</div>


	<!-- 数据表格 -->
	<div class="am-cf am-u-md-12 am-margin-top">
		<table class="am-table am-table-striped ">
			<!-- 表头 -->
			<thead>
				<tr>
					<th class="row-selected row-selected">
						<input class="check-all" type="checkbox"/>
					</th>
					<volist name="keyList" id="field">
						<th>{$field.title|htmlspecialchars}</th>
					</volist>
				</tr>
			</thead>

			<!-- 列表 -->
			<tbody>
				<volist name="list" id="e">
					<tr>
						<td>
							<input class="ids" type="checkbox" value="{$e['id']}" name="ids[]"></td>
						<volist name="keyList" id="field">
							<td>{$e[$field['name']]}</td>
						</volist>
					</tr>
				</volist>
			</tbody>
		</table>
	</div>
	<!-- 分页 -->
	<div class="am-cf am-u-md-12">{$pagination}</div>

<script type="text/javascript" src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
<script type="text/javascript">
function toggle_search(){
	$('#search_form').toggle('slide');
}

$(document).on('submit', '.form-dont-clear-url-param', function(e){
	e.preventDefault();
	var seperator = "&";
	var form = $(this).serialize();
	var action = $(this).attr('action');
	if(action == ''){
		action = location.href;
	}
	var new_location = action + seperator + form;

	location.href = new_location;

	return false;
});

$(function(){
	$('[data-role="select_text"]').change(function(){
		$('#selectForm').submit();
	});
	//模态弹窗
	$('[data-role="modal_popup"]').click(function(){
		var target_url=$(this).attr('modal-url');
		var data_title=$(this).attr('data-title');
		var target_form=$(this).attr('target-form');
		if(target_form!=undefined){
			//设置了参数时，把参数加入
			var form=$('.'+target_form);

			if (form.get(0) == undefined) {
				updateAlert('没有可操作数据。','danger');
				return false;
			} else if (form.get(0).nodeName == 'FORM') {
				query = form.serialize();
			}else if (form.get(0).nodeName == 'INPUT' || form.get(0).nodeName == 'SELECT' || form.get(0).nodeName == 'TEXTAREA') {
				query = form.serialize();
			} else {
				query = form.find('input,select,textarea').serialize();
			}
			if(!query.length){
				updateAlert('没有可操作数据。','danger');
				return false;
			}
			target_url=target_url+'&'+query;
		}
		var myModalTrigger = new ModalTrigger({
			'type':'ajax',
			'url':target_url,
			'title':data_title
		});
		myModalTrigger.show();
	});
	$('.tox-confirm').click(function(e){
		var text = $(this).attr('data-confirm');
		var result = confirm(text);
		if(result) {
			return true;
		} else {
			e.stopImmediatePropagation();
			e.stopPropagation();
			e.preventDefault();
			return false;
		}
	})
});


	$(document).ready(function () {
		$('.popup-gallery').each(function () { // the containers for all your galleries
			$(this).magnificPopup({
				delegate: 'a',
				type: 'image',
				tLoading: '正在载入 #%curr%...',
				mainClass: 'mfp-img-mobile',
				gallery: {
				enabled: true,
				navigateByImgClick: true,
				preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
			},image: {
				tError: '<a href="%url%">图片 #%curr%</a> 无法被载入.',
				titleSrc: function (item) {
				/*           return item.el.attr('title') + '<small>by Marsel Van Oosten</small>';*/
				return '';
			},
			verticalFit: false
		}
	});
});
});
</script>
</block>